//
//  ZYViewUtils.m
//  YiLin
//
//  Created by Zyark on 2018/5/31.
//  Copyleft © 2018年 Zyark. All lefts reserved.
//

#import "ZYViewUtils.h"
#import "ZYImageUtils.h"

@implementation ZYViewUtils
/**
 构造确认按钮
 @return button
 */
+(UIButton *)setupConfirmBtn{
    CGFloat height = 45;
    if(ZYiPhone5_OR_5c_OR_5s || ZYiPhone4_OR_4s){
        height = 35;
    }if(ZYiPhone6Plus_OR_6sPlus){
        height = 50;
    }
    UIButton *confirmBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, ZYSCREEN_W - 30, height)];
//    [confirmBtn setBackgroundColor:kMainColor];
    [confirmBtn setBackgroundImage:[ZYImageUtils imageWithColor:kMainColor rect:confirmBtn.bounds] forState:UIControlStateNormal];
    [confirmBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [confirmBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
    [confirmBtn.titleLabel setFont:[UIFont systemFontOfSize:16]];
    confirmBtn.layer.cornerRadius = 5;
    confirmBtn.layer.masksToBounds = YES;
    return confirmBtn;
}

/**
 构造输入框 修改个人信息界面
 @param leftTitle 左边文本
 @param placeholder 提示
 @return UITextField
 */
+(UITextField *)setupTextFieldWithLeftTitle:(NSString *)leftTitle placeholder:(NSString *)placeholder{
    UITextField *textField = [ZYViewUtils setupTextField];
    textField.backgroundColor = RGBA(248, 248, 248, 1);
    UILabel *leftLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 35)];
    leftLabel.textColor = kLabelColor;
    leftLabel.font = [UIFont systemFontOfSize:16];
    leftLabel.textAlignment = NSTextAlignmentCenter;
    textField.leftViewMode = UITextFieldViewModeAlways;
    textField.leftView = leftLabel;
    textField.placeholder = placeholder;
    leftLabel.text = leftTitle;
    NSDictionary *attributes = @{NSFontAttributeName:leftLabel.font,};
    CGSize textSize = [leftTitle boundingRectWithSize:CGSizeMake(200 , leftLabel.height)
                                           options:NSStringDrawingTruncatesLastVisibleLine attributes:attributes context:nil].size;
    leftLabel.width = textSize.width + 15;
    return textField;
}

/**
 设置左视图
 @param textField texField
 @param leftView 左视图
 */
+(void)setleftView:(UITextField *)textField leftView:(UIView *)leftView{
    textField.leftViewMode = UITextFieldViewModeAlways;
    textField.leftView = leftView;
}

+(UITextField *)setupTextField{
    UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, ZYSCREEN_W - 30, 45)];
    textField.layer.cornerRadius = 5;
    textField.layer.masksToBounds = YES;
    textField.clearButtonMode = UITextFieldViewModeWhileEditing;
    return textField;
}

@end
